package migrations

import (
	"database/sql"

	"gitee.com/sweetsunnyflower/carpooling-server-go/app/models"
	"gitee.com/sweetsunnyflower/carpooling-server-go/pkg/migrate"

	"gorm.io/gorm"
)

// http://sql2struct.atotoa.com/
func init() {

	// 乘客添加的乘车信息表
	type Rider struct {
		models.BaseModel

		UserId      uint64 `gorm:"column:user_id;comment:用户id;index;" db:"user_id" json:"user_id" form:"user_id"`
		PassengerId uint64 `gorm:"column:passenger_id;comment:乘客id" db:"passenger_id" json:"passenger_id" form:"passenger_id"`
		Name        string `gorm:"type:varchar(255);comment:乘车人姓名;" db:"name" json:"name" form:"name"`
		Phone       string `gorm:"type:varchar(20);comment:乘车人手机号;" db:"phone" json:"phone" form:"phone"`
		Gender      uint8  `gorm:"comment:性别 2:女,1:男;default:0;" db:"gender" json:"gender" form:"gender"`

		models.CommonTimestampsField
	}

	up := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.AutoMigrate(&Rider{})
	}

	down := func(migrator gorm.Migrator, DB *sql.DB) {
		migrator.DropTable(&Rider{})
	}
	migrate.Add("2023_07_18_133429_add_riders_table", up, down)
}
